package com.example.administrator.myapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.myapplication.R;

/**
 * Created by Administrator on 2016/3/19 0019.
 */
public class HelpListAdapter extends BaseAdapter {

    private String[] mTitle;
    private String[] mContent;
    private LayoutInflater mInflater;
    public HelpListAdapter(Context context,String[] title,String[] content) {
        mTitle = title;
        mContent = content;
        mInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return mTitle.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局加载成view
        View view = mInflater.inflate(R.layout.help_list_item,null);
        //找到控件
        TextView title = (TextView) view.findViewById(R.id.tv_title);
        final TextView content = (TextView) view.findViewById(R.id.tv_content);
        //给标题添加点击事件
        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                content.setVisibility(content.isShown()?View.GONE:View.VISIBLE);
            }
        });
        //绑定数据
        title.setText(mTitle[position]);
        content.setText(mContent[position]);
        return view;
    }
}
